/*
 * DiscoveryAgent.java
 *
 * Created on February 24, 2007, 2:59 PM
 */

package com.bloomingstars.bluepad.server;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;

/**
 *
 * @author toni
 */
public class BluePadDiscoveryListener implements DiscoveryListener
{
    private List remoteDevicesDiscovered = new ArrayList();
    private List servicesRecordsDiscovered = new ArrayList();
      
    public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass)
    {
        System.out.println("PIPPO");
        try
        {
            System.out.println("deviceDiscovered: " + remoteDevice.getFriendlyName(false));
        } catch (IOException e)
        {
            System.err.println("Problems while getting the friendly name of a device");
            e.printStackTrace();
        }
    }
    
    public void inquiryCompleted(int complete)
    {
        System.out.println("inquiryCompleted!");
    }
    
    public void servicesDiscovered(int transId, ServiceRecord[] records)
    {     
        System.out.println("servicesDiscovered!");
        for(int i = 0; i < records.length; i++)
        {
            ServiceRecord record = records[i];
            servicesRecordsDiscovered.add(record);
        }
    }
    
    public void serviceSearchCompleted(int transId, int complete)
    {
        System.out.println("serviceSearchCompleted!");
        if(complete == SERVICE_SEARCH_ERROR)
        {
            System.out.println("\nSERVICE_SEARCH_ERROR\n");
        }
        if(complete == SERVICE_SEARCH_COMPLETED)
        {
            System.out.println("\nSERVICE_SEARCH_COMPLETED\n");
        }
        if(complete == SERVICE_SEARCH_TERMINATED)
        {
            System.out.println("\n SERVICE_SEARCH_TERMINATED\n");
        }
        if(complete == SERVICE_SEARCH_NO_RECORDS)
        {
            System.out.println("\n SERVICE_SEARCH_NO_RECORDS\n");
        }
        if(complete == SERVICE_SEARCH_DEVICE_NOT_REACHABLE)
        {
            System.out.println("\n SERVICE_SEARCH_DEVICE_NOT_REACHABLE\n");
        }
    }
}

